﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Controllers;
using SageKing.Database.EF.Entity;
using SageKing.OpenIddict.Features;
using SageKing.OpenIddict.Middlewares;
using SageKing.OpenIddict.UI.Api; 

namespace SageKing.Extensions;

public static class ModuleExtensions
{
    public static IModule UseOpenIddictServer(this IModule module, Action<OpenIddictServerFeature>? configure = default)
    {
        module.Configure<OpenIddictServerFeature>(feature =>
        {
            configure?.Invoke(feature);
        }); 

        return module;
    } 

    public static WebApplication UseSageKingTenantMiddleware(this WebApplication app)
    {
        app.UseMiddleware<TenantMiddleware>();
        return app;
    }

    public static OpenIddictBuilder AddTemplateStore(this OpenIddictBuilder builder, Action<TemplateStoreOptions> storeOptionsAction = null
)
    {
        builder.Services
          .AddTemplateStore<TemplateContext>(storeOptionsAction);

        return builder;
    }
}
